//
//  GMLNaviView.m
//  Camera
//
//  Created by gml on 2018/11/1.
//  Copyright © 2018年 gml. All rights reserved.
//

#import "GMLGradientNaviView.h"

@interface GMLGradientNaviView()
@property (nonatomic,strong) CAGradientLayer *gradientLayer;
@property (nonatomic,weak) UIButton *leftBtn;
@property (nonatomic,weak) UIButton *rightBtn;
@end

@implementation GMLGradientNaviView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        // 1 背景色
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = self.bounds;
        //  [UIColor colorWithRed:52.0 / 255.0 green:104.0 / 255.0 blue:206.0 / 255.0 alpha:1]
        // 105,105,105
        gradientLayer.colors   = @[(__bridge NSArray * _Nullable)(UIColorFromRGB(0x474747).CGColor), (__bridge NSArray * _Nullable)(UIColorFromRGB(0x1E1E1E).CGColor)];;
        // 颜色分割线位置( 默认 0，1 )
        // 颜色分割线位置( 默认 0，1 )
        gradientLayer.locations    = @[@(0),@(1)];
        // 起始点 坐标是 左上 （0，0）  右下 （1，1）
        gradientLayer.startPoint  = CGPointZero;
        // 结束点
        gradientLayer.endPoint = CGPointMake(1, 0);
        [self.layer addSublayer:gradientLayer];
        self.gradientLayer = gradientLayer;
        
        // 左边按钮
        UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, frame.size.height-40, 40,40)];
//        leftBtn.center = CGPointMake(15+leftBtn.bounds.size.width * 0.5, y);
        [leftBtn setImage:[UIImage imageNamed:@"navi_user_icon"] forState:UIControlStateNormal];
        [leftBtn addTarget:self action:@selector(leftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:leftBtn];
        self.leftBtn = leftBtn;
        
        // 右边按钮
        UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width - leftBtn.bounds.size.width - 15, frame.size.height-40, 40,40)];
//        rightBtn.center = CGPointMake(rightBtn.frame.origin.x+rightBtn.frame.size.width * 0.5, y);
        [rightBtn setImage:[UIImage imageNamed:@"navi_more_icon"] forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:rightBtn];
        self.rightBtn = rightBtn;
        
        // title
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(leftBtn.frame), SAFE_SCREEN_TOP,frame.size.width - CGRectGetMaxX(leftBtn.frame)-rightBtn.bounds.size.width-15-15, frame.size.height-SAFE_SCREEN_TOP)];
        titleLab.text = @"动画+手势";
        titleLab.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];
        titleLab.textColor = [UIColor whiteColor];
        titleLab.textAlignment = NSTextAlignmentCenter;
        [self insertSubview:titleLab belowSubview:leftBtn];
  
    }
    return self;
}
- (void)setNavAlpha:(CGFloat)navAlpha
{
    _navAlpha = navAlpha;
//    self.alpha = navAlpha;
    self.gradientLayer.opacity = navAlpha;
}

#pragma mark --action
- (void)leftBtnAction:(UIButton *)left
{
    if (self.leftBlcok) {
        self.leftBlcok(left);
    }
}
- (void)rightBtnAction:(UIButton *)right
{
    if (self.rightBlcok) {
        self.rightBlcok(right);
    }
}

@end
